package com.elitel.frame.web.cfgtableinfo.controller;

import com.elitel.common.core.domain.JsonResult;
import com.elitel.frame.web.cfgtableinfo.entity.CfgTableInfo;
import com.elitel.frame.web.cfgtableinfo.entity.CfgTableInfoVO;
import com.elitel.frame.web.cfgtableinfo.service.CfgTableInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 数据库元数据表信息(CfgTable)表控制层
 *
 * @author makejava
 * @since 2025-05-19 16:14:10
 */
@RestController
@RequestMapping("cfgTableInfo")
public class CfgTableInfoController {
    /**
     * 服务对象
     */
    @Resource
    private CfgTableInfoService cfgTableInfoService;

    @GetMapping("listByDbKey")
    public JsonResult<List<CfgTableInfoVO>> listByDbKey(String dbKey) {
        CfgTableInfo cfgTableInfo = new CfgTableInfo();
        cfgTableInfo.setDtConn(dbKey);
        List<CfgTableInfo> list = cfgTableInfoService.list(cfgTableInfo);
        // 转为CfgTableInfoVO 此处转一下属于接口约束
        List<CfgTableInfoVO> collect = list.stream().map(item -> {
            CfgTableInfoVO cfgTableInfoVO = new CfgTableInfoVO();
            cfgTableInfoVO.setTableId(item.getDtConfigId());
            cfgTableInfoVO.setTableCode(item.getDtName());
            cfgTableInfoVO.setTableName(item.getDtNameCn());
            return cfgTableInfoVO;
        }).collect(Collectors.toList());
        return JsonResult.success(collect);
    }

}

